import datetime

from django.db import models


# Create your models here.

class Publish(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=128)
    address = models.CharField(max_length=128)


# 一对多的关系要建立在多的一方
class Book(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=128)
    price = models.DecimalField(max_digits=7, decimal_places=2)
    create_time = models.DateField(auto_now_add=True)
    publish = models.ForeignKey(to="Publish", to_field="id", on_delete=models.CASCADE)
    auther = models.ManyToManyField(to="Auther")


class Auther(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=128)
    address = models.CharField(max_length=128)
    autherdetail = models.OneToOneField(to="Autherdetail", on_delete=models.CASCADE, to_field="id", null=True)


class Autherdetail(models.Model):
    id = models.AutoField(primary_key=True)
    phone = models.IntegerField(max_length=12)
    email = models.EmailField()
